<?php
namespace App\Admin\Extra\Player;

use Illuminate\Http\Request;
class Account{

    public static $fields = ['is_seal_number' =>'是否封号', 'seal_number_time_limit' =>'封号时长', 'freeze'=> '冻结'];
    
    public function ajaxAct(Request $request){
        try {
            $arr = $request->all();
            
            $actData = [];
            $account = $request->get('account', 0);
            
            if (empty($account)) {
                throw new \Exception('account is empty', 505);
            }

            foreach ($arr as $attr => $val) {
                isset(self::$fields[$attr]) && $actData[$attr] = $val;
            }

            $ret = \DB::connection('mysql_bgac')->table('account_info')->where('account', $account)->update($actData);

            return ['code' => 0, 'msg' => '操作成功'];

        }catch(\Exception $e) {
            return ['code'=> $e->getCode()?:501, 'msg' => $e->getMessage()];
        }
    }
}
